define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'app/intel/index' + location.search,
                    add_url: 'app/intel/add',
                    edit_url: 'app/intel/edit',
                    del_url: 'app/intel/del',
                    multi_url: 'app/intel/multi',
                    table: 'app_intel',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'verifytime',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'usergroup.group.name', title: __('Group.group_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname')},
                        // {field: 'rtype', title: __('Rtype'), visible:false, searchList: {"0":__('Rtype 0'),"1":__('Rtype 1'),"2":__('Rtype 2'),"3":__('Rtype 3'),"4":__('Rtype 4')}},
                        // {field: 'rtype_text', title: __('Rtype'), operate:false},
                        // {field: 'rid', title: __('Rid')},
                        // {field: 'column', title: __('Column'), visible:false, searchList: {"0":__('Column 0'),"1":__('Column 1'),"2":__('Column 2'),"3":__('Column 3')}},
                        // {field: 'column_text', title: __('Column'), operate:false},
                        // {field: 'applabel.name', title: __('Applabel.name')},
                        {field: 'commentnum', title: __('Commentnum'), operate:false},
                        {field: 'pvnum', title: __('Pvnum'), operate:false},
                        {field: 'sharenum', title: __('Sharenum'), operate:false},
                        {field: 'praisenum', title: __('Praisenum'), operate:false},
                        {field: 'recommendswitch', title: __('Recommendswitch'), searchList: {"0":__('Recommendswitch 0'),"1":__('Recommendswitch 1')}, formatter:Table.api.formatter.toggle},
                        {field: 'verify', title: __('Verify'), visible:false, searchList: {"0":__('Verify 0'),"1":__('Verify 1'),"2":__('Verify 2')}},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'verify_text', title: __('Verify'), operate:false},
                        {field: 'verifytime', title: __('Verifytime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // buttons: [
            //        {
            //            name: 'sh',
            //            text: '审核',
            //            icon: 'fa fa-eye-slash',
            //            classname: 'btn btn-xs btn-warning btn-dialog',
            //            url: function (row, column) {
            //                return "app/intel/verify?id=" + row.id;
            //            }
            //        }],
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        verify: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
